const arr = [
    {
        id: 33,
        name: '请假申请',
        type: 'user',
        userRole: 'manager',
        deptRole: null,
        next: {
            id: 34,
            name: '请假申请',
            type: 'user',
            userRole: 'manager',
            deptRole: null
        }
    },
    {
        id: 34,
        name: '请假申请',
        type: 'user',
        userRole: 'manager',
        deptRole: null,
        next: {
            id: 35,
            name: '请假申请',
            type: 'dept',
            userRole: null,
            deptRole: 'personnel'
        }
    },
    {
        id: 35,
        name: '请假申请',
        type: 'dept',
        userRole: null,
        deptRole: 'personnel',
        next: {
            id: 36,
            name: '请假申请',
            type: 'user',
            userRole: 'director',
            deptRole: null
        }
    },
    {
        id: 36,
        name: '请假申请',
        type: 'user',
        userRole: 'director',
        deptRole: null,
        next: null
    }
]

const list2tree = (list) => {
    const map = new Map();
    for (const item of list) {
        map.set(item.next?.id, item)
    }
    let head = null;
    while (map.size) {
        const node = map.get(head?.id);
        node.next = head
        map.delete(head?.id)
        head = node;
    }
    return head
}
console.log(list2tree([]))